package com.ltv.xiangqibook.web;

import java.util.Date;

import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Text;

/**
 * This class defines the methods for basic operations of create, update & retrieve
 * for the post entity
 * 
 * @author
 *
 */
public class Post {

	/**
	 * Create the post
	 * 
	 * @param id
	 *          : id of the post
	 * @param game_id
	 *          : game id
	 * @param author
	 *          : author
	 * @param content
	 *          : content
	 * @param created_time
	 *          : created time
	 * @return persisted post
	 */
	public static void createPost(Long id, String game_id, String author, Text content, Date created_time) {
		Entity post = new Entity("posts", id);

		post.setProperty("game_id", game_id);
		post.setProperty("author", author);
		post.setProperty("content", content);
		post.setProperty("created_time", created_time);

		Util.persistEntity(post);
	}

	/**
	 * Return all the posts by game_id
	 * 
	 * @return posts
	 */
	public static Iterable<Entity> getAllPostsByGameId(String game_id) {
		return Util.listEntities("posts", "game_id", game_id);
	}

}
